package com.livegoods.rabbitmq.listener;

import com.livegoods.commons.pojo.LivegoodsPublistMessage;
import com.livegoods.rabbitmq.service.BuyactionService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QueueListener {

    @Autowired
    private BuyactionService buyactionService;

    @RabbitListener(
            bindings = {@QueueBinding(
                    exchange = @Exchange("${livegoods.rabbitmq.exchange}"),
                    value = @Queue(name = "${livegoods.rabbitmq.buyaction.queue}",autoDelete = "false"),
                    key = "${livegoods.rabbitmq.buyaction.routingKey}"
            )}
    )
    public Boolean buyaction(LivegoodsPublistMessage message){
        System.out.println("message111 = " + message);

        String houseId = message.getHouseId();
        String username = message.getUsername();
        System.out.println("username = " + username);
        System.out.println("houseId = " + houseId);
        Boolean resutl = buyactionService.buyaction(houseId,username);

        return resutl;
    }
}
